package com.atguigu.guli.service.cms.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.cms.entity.AdType;
import com.atguigu.guli.service.cms.service.AdTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 推荐位 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-11-09
 */
@RestController
@RequestMapping("/cms/ad-type")
public class AdminAdTypeController {
    @Autowired
    AdTypeService adTypeService;
    //新增广告
    @PostMapping("insertAD")
    public R insertAD(@RequestBody AdType ad){
        adTypeService.save(ad);
        return  R.ok();
    }

    //删除广告
    @DeleteMapping("deleteById/{id}")
    public  R deleteById(@PathVariable String id){
        adTypeService.removeById(id);
        return R.ok();
    }

    //修改广告
    @PutMapping("update")
    public R update(@RequestBody AdType ad){
        adTypeService.updateById(ad);
        return R.ok();
    }
    //根据指定的id查询广告
    @GetMapping("findById/{id}")
    public R findById(@PathVariable String id){
        AdType ad = adTypeService.getById(id);
        return R.ok().data("item",ad);
    }
}

